<template>
  <div class="container">
    <div class="login-wrapper">
      <div class="header">Login</div>
      <div class="form-wrapper">
        <input
          type="text"
          name="username"
          placeholder="Username"
          class="input-item"
          v-model="loginForm.username"
        />
        <input
          type="password"
          name="password"
          placeholder="Password"
          class="input-item"
          v-model="loginForm.password"
        />
        <div class="btn" @click="login">Login</div>
      </div>
      <div class="msg a" @click="register">
        还没有账号？<a href="#">点击前往注册</a>
      </div>
    </div>
  </div>
</template>

  <script>
export default {
  data() {
    return {
      loginForm: {
        username: "派大星",
        password: "123",
        session_id: "",
      },
    };
  },
  created() {},
  mounted() {},
  methods: {
    login() {
      if (this.loginForm.username === "" || this.loginForm.password === "") {
        this.$toast.showMessage("请输入用户名和密码");
      } else {
        this.$http
          .post("login", this.loginForm)
          .then((res) => {
            console.log(res.data);
            //登录失败
            if (res.data.code === 0) {
              this.$toast.showMessage(res.data.msg);
            } else {
              //登录成功
              this.$store.commit("user/setUser", res.data.data);
              this.$router.push("../My");
              this.$toast.showMessage("登录成功");
            }
          })
          .catch(() => {
            this.$toast.showMessage("登录失败");
          });
      }
    },
    register() {
      //当用户点击前往注册，就跳转到注册页面
      this.$router.push("../user/register");
    },
  },
};
</script>

<style scoped>
.container {
  height: 90vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(
    to right,
    rgba(102, 88, 88, 0.125),
    rgba(156, 211, 219, 0.262)
  );
}
.msg {
  text-align: center;
  line-height: 88px;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.6);
}
.login-wrapper {
  background-color: rgba(255, 255, 255, 0.95);
  width: 390px;
  height: 620px;
  border-radius: 15px;
  padding: 0 50px;
  box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.2);
}

.header {
  font-size: 38px;
  font-weight: bold;
  text-align: center;
  line-height: 200px;
}

.form-wrapper {
  margin-top: 50px;
}

.input-item {
  display: block;
  width: 100%;
  margin-bottom: 20px;
  border: 0;
  padding: 10px;
  border-bottom: 1px solid rgb(128, 125, 125);
  font-size: 15px;
  outline: none;
}

.btn {
  text-align: center;
  padding: 10px;
  margin: 0 auto;
  width: 100%;
  margin-top: 40px;
  background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.btn:hover {
  background-image: linear-gradient(to right, #fbc2eb, #a6c1ee);
}
.a {
  text-decoration-line: none;
  color: #abc1ee;
  transition: color 0.3s ease;
}
a:hover {
  color: #fbc2eb;
}
</style>
